package com.xk.demo.department.control;

import com.xk.demo.common.control.BaseController;
import com.xk.demo.department.entity.SearchDepartmentEntity;
import com.xk.demo.department.service.DepartmentService;
import com.xk.demo.mybatis.entity.PtDepartmentEntity;
import com.xk.demo.mybatis.entity.PtUserEntity;
import com.xk.demo.mybatis.flexigrid.PadingRstType;
import com.xk.demo.mybatis.flexigrid.PagingBean;
import com.xk.demo.role.service.RoleService;
import com.xk.demo.user.entity.UserSearchEntity;
import org.apache.ibatis.annotations.Param;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.security.access.annotation.Secured;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;

@Controller
@RequestMapping("/department")
public class DepartmentController extends BaseController{
    private Logger logger =  LogManager.getLogger(this.getClass().getName());
    @Resource
    private DepartmentService departmentService;
    @Secured("ROLE_gqgy_data_department")
    @RequestMapping("/departmentPage")
    public  String departmentPage(){
        return "/department/departmentPage";
    }

    @RequestMapping("/getDepartmentInfoListByPage")//分页
    @ResponseBody
    public PadingRstType<PtDepartmentEntity> getDepartmentInfolistByPage(SearchDepartmentEntity search, PagingBean paging){
        logger.info(search);
        PadingRstType<PtDepartmentEntity> ptDepartmentEntityPadingRstType = departmentService.getDepartmentInfoListByPage(search,paging);
        return ptDepartmentEntityPadingRstType;
    }

    @RequestMapping("/deleteDepartmentById")
    @ResponseBody
    public String deleteDepartmentById(String depUuid){
        logger.info("depUuid"+depUuid);
        departmentService.deleteDepartmentById(depUuid);
        return getSuccessMessag("department.delete.sucess");
    }

    /*绑定子国电部门*/
    @RequestMapping("/updatePtDepartmentBelongCenter")
    @ResponseBody
    public Json updatePtDepartmentBelongCenter(@RequestParam("branchName") String branchName){
        logger.info("branchName"+branchName);
        String s = departmentService.updatePtDepartmentBelongCenter(branchName);
        Json json =new Json();
        json.setValue(s);
        return json;
    }

    /*解除绑定子国电部门*/
    @RequestMapping("/clearBoundPtDepartmentByBranchName")
    @ResponseBody
    public Json clearBoundPtDepartmentByBranchName(@RequestParam("branchName") String branchName){
        logger.info("branchName"+branchName);
        logger.info("muyinosnggggg");
        String s = departmentService.clearBoundPtDepartmentByBranchName(branchName);
        Json json =new Json();
        json.setValue(s);
        return json;
    }
}
